package service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.Command_dao;
import entity.Command;
import entity.CommandContent;
import enums.travelenums;
import service.Command_service;

@Service
public class Command_service_impl implements Command_service {

	@Autowired
	private Command_dao command_dao;
	
	@Override
	public String getDescription(String command) {
		if(command.equals("帮助")){ 
			List<Command> list=command_dao.getDescription(null,null);
			StringBuffer sBuffer=new StringBuffer();
			for (Command command2 : list) {
				sBuffer.append("回复【"+command2.getCommand()+"】查看相关内容"+"<br>");
			}
			return sBuffer.toString();
		}
		List<Command> list=command_dao.getDescription(command,null);
		if(list.size()>0){
			StringBuffer sBuffer=new StringBuffer();
			for (Command command2 : list) {
				List<CommandContent> list2=command2.getCommandcontent_list();
				for (CommandContent commandContent : list2) {
					sBuffer.append("回复【"+commandContent.getDescription()+"】查看相关内容"+"<br>");
				}
			}
			return sBuffer.toString();
		}else {
			return travelenums.NOTFOUND.getInfo();
		}
	}

	@Override
	public String getContent(String description) {
		CommandContent commandContent=command_dao.getContent(description);
		if(commandContent!=null){
			return commandContent.getContent();
		}
		return travelenums.NOTFOUND.getInfo();
	}

	@Override
	public List<Command> CommandList() {
		return command_dao.getDescription(null,null);
	}

	@Override
	public Command getCommandById(Integer id) {
		List<Command> list=command_dao.getDescription(null, id);
		return list.get(0);
	}

	@Override
	public boolean updateCommandContent(CommandContent commandContent) {
		if(commandContent!=null){
			return command_dao.updateCommandContent(commandContent);
		}
		return false;
	}

	@Override
	public boolean updateCommand(Command command) {
		if(command!=null){
			return command_dao.updateCommand(command);
		}
		return false;
	}

	@Override
	public boolean saveCommandContent(CommandContent commandContent) {
		if(commandContent!=null){
			return command_dao.saveCommandContent(commandContent);
		}
		return false;
	}

	@Override
	public boolean saveCommand(Command command) {
		if(command!=null){
			return command_dao.saveCommand(command);
		}
		return false;
	}

	@Override
	public boolean deleteCommand(Integer id) {
		if(id!=null){
			return command_dao.deleteCommand(id);
		}
		return false;
	}

	@Override
	public boolean deleteCommandContent(Integer id) {
		if(id!=null){
			return command_dao.deleteCommandContent(id);
		}
		return false;
	}

}
